<template>
  <view style="width: 100%; height: 100vh; background-color: #000; display: flex; align-items: center; justify-content: center">
    <view style="height: 100%; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; margin-top: -150px">
      <view style="margin-left: auto" @click="closebigPop">
        <u-icon size="68" name="close-circle"></u-icon>
      </view>
      <!-- <view style="color: #fff;">送你返利金额</view> -->
      <view style="width: 80%; height: 500rpx; background-color: #fff; height: 40%; text-align: center; border-radius: 20rpx; padding: 20rpx; position: relative; overflow: hidden">
        <!--    <span class="sblzh">可提现</span> -->
        <view v-if="aadddcc" style="height: 40%; width: 100%; display: flex; align-items: center; justify-content: center; font-size: 40rpx; font-weight: bold">
          <view style="width: 100%">
            <view style="width: 100%">
              您的好友 <span style="color: red; white-space: nowrap">{{ nickName }}-{{ yuanphone }}</span></view
            >
            <view
              >送您 <span style="color: red">{{ integralGive }}</span> 平台积分</view
            >
            <span style="font-size: 30rpx; color: #333; font-weight: normal">可用来消费抵扣</span>
          </view>
        </view>
        <u-line></u-line>

        <view style="height: 60%; display: flex; flex-direction: column; align-items: center; justify-content: center">
          <view class="textsb">
            <view>领取人</view>
            <view style="display: flex; align-items: center">
              <image class="avatar" :src="userInfo.avatar.includes('https') ? userInfo.avatar : getImg + userInfo.avatar" v-if="userInfo.avatar"></image>
              <image v-else class="avatar" src="https://www.wantongkonggu.cn/crmebimage/profile/upload/2025/03/20/f_20250320164147A002.png" mode=""></image>
              <span v-if="userInfo.nickname"> {{ userInfo.nickname }}</span>
            </view>
          </view>
          <view class="textsb">
            <view>领取方式</view>
            <view>个人中心-平台积分</view>
          </view>
          <span style="color: red">预计3~5分钟到账，请耐心等待</span>
          <span style="color: red">本次不领取视为作废</span>
          <view style="margin-top: 50rpx; width: 90%" @click="shenqingtixian">
            <u-button color="#fa642f" style="margin-top: 50rpx" type="success" text="立即领取"></u-button>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import { getUserInfo, transferToUsers, transConfirmOrCancel, receiveCode } from "../../../utils/request_api";
export default {
  data() {
    return {
      userInfo: {},
      integralGive: "",
      aadddcc: false,
      numb: 1,
      nickName: "",
      yuanphone: "",
      shareCode: "",
    };
  },
  onLoad(options) {
    console.log("🚀 ~ onLoad ~ options:", options);
    this.integralGive = options.amount;
    this.nickName = options.nickName;
    this.yuanphone = options.yuanphone;
    this.shareCode = options.shareCode;
    this.aadddcc = true;
    this.initUser();

    // this.debouncedShenqingtixian = this.debounce(this.shenqingtixian, 1000); // 初始化防抖方法
  },
  methods: {
    /* 获取用户信息 */
    initUser() {
      getUserInfo().then((res) => {
        this.userInfo = res.data;
      });
    },
    debounce(func, wait) {
      let timeout;
      return function (...args) {
        const context = this;
        clearTimeout(timeout);
        timeout = setTimeout(() => func.apply(context, args), wait);
      };
    },
    shenqingtixian() {
      if (this.numb == 1) {
        this.numb = 2;
        uni.showLoading({
          title: "加载中",
        });
        /* if (this.integralGive && this.integralGive < 0.1) {
          this.numb = 1;
          uni.showToast({ title: "提现金额大于0.1！", icon: "none" });
          return;
        } */
        receiveCode({ ebUserIdFetch: uni.getStorageSync("uid"), fetchStatus: 1, shareCode: this.shareCode })
          .then((res) => {
            if (res.code == 200) {
              if (res.data.boolean === true) {
                uni.showToast({
                  icon: "none",
                  title: "领取成功！",
                });
                setTimeout(() => {
                  uni.redirectTo({
                    url: "/pages_h5/myCenter/components/user_integral",
                  });
                }, 1000);

                uni.hideLoading();
              } else {
                uni.showToast({
                  icon: "none",
                  title: "领取失败！" + res.data.msg,
                });
                setTimeout(() => {
                  uni.navigateBack({ delta: 1 });
                }, 1000);
              }
            }
            this.numb = 1;
            uni.hideLoading();
          })
          .catch(() => {
            this.numb = 1;
            uni.showToast({
              icon: "none",
              title: "领取失败！",
            });
            uni.hideLoading();
          });
      } else {
        uni.showToast({
          icon: "none",
          title: "请勿重复操作！",
        });
      }
    },

    closebigPop() {
      receiveCode({ ebUserIdFetch: uni.getStorageSync("uid"), fetchStatus: 2, shareCode: this.shareCode }).then((res) => {
        uni.reLaunch({
          url: "/pages_h5/index/index", // 跳转目标页面路径
          success: function () {
            console.log("成功关闭所有页面并跳转到新页面");
          },
        });
      });
    },
  },
};
</script>

<style scoped>
.lzhsb {
  box-shadow: 0px 0 15px 0 burlywood inset;
  border-radius: 10rpx;
  width: 60%;
  height: 60rpx;
}
.textsb {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 90%;
  margin: 10rpx 0;
}
.sblzh {
  /* width: 90px; */
  height: 45px;
  font-size: 22px;
  text-align: center;
  line-height: 45px;
  color: #fa9a96;
  padding: 0 10px;
  letter-spacing: 1.5px;
  border: 2px solid #fa9a96;
  border-radius: 38% 50% 38% 50%;
  transform: rotate(20deg);
  position: absolute;
  right: -10px;
  font-family: fangsong;
  font-weight: bold;
}
.avatar {
  width: 40rpx;
  height: 40rpx;
  border-radius: 50%;
  margin-right: 10rpx;
}
</style>
